package com.qf.lanzhou.shop.api.service.impl;

import com.qf.lanzhou.shop.api.dao.HistoryMapper;
import com.qf.lanzhou.shop.api.service.HistoryService;
import com.qf.lanzhou.shop.pojo.entity.Goods;
import com.qf.lanzhou.shop.pojo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Nerly
 * @Date 2021/1/11 20:02
 * @JDK 1.8
 * @Version 1.0
 */
@Service
public class HistoryServiceImpl implements HistoryService {
    @Autowired
    private HistoryMapper historyMapper;

    @Override
    public List<Goods> selectByUserId(User user) {
        List<Goods> goodsList = historyMapper.selectByUserId(user);
        return goodsList;
    }

    @Override
    public int walk(User user, Goods goods) {
        Goods result = historyMapper.selectByUserIdAndGoodsId(user, goods);
        if (null!=result){
            historyMapper.deleteByGoodsId(user,goods);
        }
        int insertResult = historyMapper.insert(user, goods);
        return insertResult;
    }
}
